/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package threads;

import java.awt.*;
import java.util.Random;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Jakim
 */
public class MyThread implements Runnable{

    Label lbl;
    String name;
    int time;
    Random r;

    public MyThread(String name, Label lbl){
        this.name = name;
        this.lbl = lbl;
        this.r = new Random();
        this.time = (r.nextInt(2000) + 1000) * 10;
    }

    public void run() {

        try {
            for (int i = 1; i < 4; i++){
                this.lbl.setText("This thread named "+ this.name + " will sleep for " + this.time / 1000 +" seconds.");
                ((Component)  this.lbl).repaint();
                this.lbl.setVisible(true);
                Thread.sleep(this.time);
                this.lbl.setText("This thread named was its " + i + " run ");
                Thread.sleep(this.time);
            }

        } catch (InterruptedException ex) {
            Logger.getLogger(MyThread.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
